package service;

import java.util.List;

import bean.admin;
import bean.adminRowMapper;
import common.BaseDAO;

public class adminDAO extends BaseDAO{
	//添加管理员方法
	public void addadmin(admin admin) {
		String sql="insert into admin_info(admin,password,name,tel,mail,permission) values(?,?,?,?,?,?)";
		this.update(sql,admin.getAdmin(),admin.getPassword(),admin.getName(),admin.getTel(),admin.getMail(),admin.getPermission());
	}
	//查询全部管理员信息
	public List<admin> getAdminAll(){
		String sql="select * from admin_info";
	    return this.query(sql,new adminRowMapper());
	}
	//通过ID删除管理员
	public void deleteAdminById(int admin_id) {
		String sql="update admin_info set whether_position=0 where admin_id=?";
	}
	//根据关键字模糊查询
	public List<admin> getAdminByChar(String zi){
		String sql="select * from admin_info where name like ?";
	    return this.query(sql,new adminRowMapper(),"%"+zi+"%");
	}
	
	//根据电话查询单个管理员信息
		public List<admin> getAdminByPhone(String admin_phone){
			String sql="select * from admin_info where tel=?";
		    return this.query(sql,new adminRowMapper(),admin_phone);
		}
	
	//登录校验
	public admin htLogin(String name,String password) {
		String sql="select * from admin_info where admin=? and password=?";
		List<admin> list=this.query(sql, new adminRowMapper(), name,password);
		if(list!=null&&list.size()>0){
		  return list.get(0);
		}
		return null;
	}
	//登录校验获取是否在职
	@SuppressWarnings("null")
	public int getWhether_position(String name,String password) {
		String sql="select * from admin_info where admin=? and password=?";
		List<admin> list=this.query(sql, new adminRowMapper(), name,password);
		if(list!=null&&list.size()>0){
		  return list.get(0).getWhether_position();
		}
		return (Integer) null;
	}
	//通过ID和密码获取电话
	public String getTel(String name,String password) {
		String sql="select * from admin_info where admin=? and password=?";
		List<admin> list=this.query(sql, new adminRowMapper(), name,password);
		if(list!=null&&list.size()>0){
		  return list.get(0).getTel();
		}
		return null;
	}
	//通过ID和密码获取管理员职位
		public int getPosition(String name,String password) {
			String sql="select * from admin_info where admin=? and password=?";
			List<admin> list=this.query(sql, new adminRowMapper(), name,password);
			if(list!=null&&list.size()>0){
			  return list.get(0).getPermission();
			}
			return (Integer) null;
		}

}
